﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpAlgorithm
{
    class FlippingCoins
    {
        public FlippingCoins()
        {
            string[] input = TestConsole.ReadLine().Split(' ');
            int coinCount = Int32.Parse(input[0]);
            int orderCount = Int32.Parse(input[1]);
            byte[] coin = new byte[coinCount];
            for (int i = 0; i < orderCount; i++)
            {
                input = TestConsole.ReadLine().Split(' ');
                int order = Int32.Parse(input[0]);
                int start = Int32.Parse(input[1]);
                int end = Int32.Parse(input[2]);
                int count = 0;
                if (order == 0)
                {
                    for (int j = start; j <= end; j++)
                    {
                        if (coin[j] == 0)
                        {
                            coin[j] = 1;
                        }
                        else
                        {
                            coin[j] = 0;
                        }
                    }
                }
                else
                {
                    count = 0;
                    for (int j = start; j <= end; j++)
                    {
                        if (coin[j] == 1)
                        {
                            count++;
                        }
                    }
                    Console.WriteLine(count);
                }
            }
        }
    }
}
